Skip to content

Update Chapter6#9

Open
bissenbay wants to merge 1 commit intoPacktPublishing:masterfrom
bissenbay:update-chapter6
Open

Update Chapter6#9
bissenbay wants to merge 1 commit intoPacktPublishing:masterfrom
bissenbay:update-chapter6

Conversation

@bissenbay
Copy link
Copy Markdown

No description provided.

}

void createNewTask(Plan plan, [String description]) {
void createNewTask(Plan plan, [String? description]) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I leave it as String description, then I have a conflict on controller.createNewTask(plan); in _buildAddTaskButton function because we are not sending description in there, so that's I made this to be optional. However, I think there might be better way to handle this.

class Plan {
final int id;
String name = '';
String name;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this assignment might be redundant as we are assigning it in the constructor on line 9.

: id = model.id,
name = model?.data['name'],
tasks = model?.data['task']
name = model.data['name'] ?? '',
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting type 'Null' is not a subtype of type 'String', so I decided to solve this way.


static PlanController of(BuildContext context) {
PlanProvider provider = context.dependOnInheritedWidgetOfExactType<PlanProvider>();
final provider = context.dependOnInheritedWidgetOfExactType<PlanProvider>()
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I specify PlanProvider, I get an error A value of type 'PlanProvider?' can't be assigned to a variable of type 'PlanProvider'.

@bissenbay bissenbay force-pushed the update-chapter6 branch 2 times, most recently from 96bc8bc to d133e67 Compare October 10, 2021 06:26
Copy link
Copy Markdown
Author

@bissenbay bissenbay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ bkayfitz PTAL!

}

void addTask(Plan plan, String description) {
final id = plan.tasks.last?.id ?? 0 + 1;
Copy link
Copy Markdown
Author

@bissenbay bissenbay Oct 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, I had this conflict The receiver can't be null, so the null-aware operator '?.' is unnecessary.. However, if I remove ?. before id, then I get The left operand can't be null, so the right operand is never executed.. After that, the suggested looks like this final id = plan.tasks.last.id;. However, it breaks my code, so I actually came up with below code.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you found any solution to this issue?

Copy link
Copy Markdown
Author

@bissenbay bissenbay Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amkfat lines 31 to 34 are the solution I came up with

@bissenbay bissenbay force-pushed the update-chapter6 branch 2 times, most recently from fcc658b to fd9f5a2 Compare October 14, 2021 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants